package ipebg.mzk.common.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.hql.internal.ast.QueryTranslatorImpl;
import org.hibernate.internal.SessionFactoryImpl;

import java.util.Collections;

/**
 * Created by LT on 2016/5/19.
 */
public class HqlUtil {
    public static String hql2Sql(Session session,String hql) {
        SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory();
        QueryTranslatorImpl queryTranslator=new QueryTranslatorImpl(hql,hql, Collections.EMPTY_MAP,sessionFactory);
        queryTranslator.compile(Collections.EMPTY_MAP, false);
        return queryTranslator.getSQLString();
    }
}
